package demo08;

import red.OpenMode;

import java.util.ArrayList;
import java.util.Random;

public class RandomMode implements OpenMode {
    @Override
    public ArrayList<Integer> divide(int totalMoney, int totalCount) {
        ArrayList<Integer> list=new ArrayList<>();
        Random random=new Random();
        int leftMoney=totalMoney;
        int leftCount=totalCount;
        for (int i = 0; i < totalCount-1; i++) {
            int money=1+random.nextInt(leftMoney/leftCount*2);
            list.add(money);
            leftMoney=leftMoney-money;
            leftCount--;
        }
        list.add(leftMoney);
        return list;
    }
}
